home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / TIMER.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-07  |  2.1 KB  |  69 lines

  1. #ifndef    _TIMER_H
  2. #define    _TIMER_H
  3.  
  4. #ifndef    _GLOBAL_H
  5. #include "global.h"
  6. #endif
  7.  
  8.  
  9. /* Software timers
  10.  * There is one of these structures for each simulated timer.
  11.  * Whenever the timer is running, it is on a linked list
  12.  * pointed to by "Timers". The list is sorted in ascending order of
  13.  * expiration, with the first timer to expire at the head. This
  14.  * allows the timer process to avoid having to scan the entire list
  15.  * on every clock tick; once it finds an unexpired timer, it can
  16.  * stop searching.
  17.  *
  18.  * Stopping a timer or letting it expire causes it to be removed
  19.  * from the list. Starting a timer puts it on the list at the right
  20.  * place.
  21.  */
  22. struct timer {
  23.     short magic1;        /* for sanity checking */
  24. #define TIMER_MAGIC1    0x1234
  25.     struct timer *next;    /* Linked-list pointer */
  26.     int32 duration;        /* Duration of timer, in ticks */
  27.     int32 expiration;    /* Clock time at expiration */
  28.     void (*func) (void *);    /* Function to call at expiration */
  29.     void *arg;        /* Arg to pass function */
  30.     char state;        /* Timer state */
  31. #define    TIMER_STOP    0
  32. #define    TIMER_RUN    1
  33. #define    TIMER_EXPIRE    2
  34.     void  *theproc;        /* Process owning the timer
  35.                    (actually a struct proc *) */
  36.     short magic2;        /* for sanity checking */
  37. #define TIMER_MAGIC2    0x4321
  38. };
  39. #define    NULLTIMER    (struct timer *)0
  40.  
  41. #ifndef    MSPTICK
  42. #define    MSPTICK        20        /* Milliseconds per tick */
  43. #endif
  44.  
  45. /* Useful user macros that hide the timer structure internals */
  46. #define    dur_timer(t)    ((t)->duration*MSPTICK)
  47. #define    run_timer(t)    ((t)->state == TIMER_RUN)
  48.  
  49. extern volatile int Tick;
  50. extern void (*Cfunc[]) (void);    /* List of clock tick functions */
  51.  
  52. /* In timer.c: */
  53. void kalarm (int32 ms);
  54. int32 read_timer (struct timer *t);
  55. void set_timer (struct timer *t,int32 x);
  56. void start_timer (struct timer *t);
  57. void start_detached_timer (struct timer *t);
  58. void stop_timer (struct timer *timer);
  59. char *tformat (int32 t);
  60. int32 rdclock (void);
  61.  
  62. /* In hardware.c: */
  63. #ifdef MSDOS
  64. int32 msclock (void);
  65. int32 secclock (void);
  66. #endif        /* else, defined in unixtm.h */
  67.  
  68. #endif    /* _TIMER_H */
  69.